<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <div>
            <table border="1">
                <thead>
                    <tr>
                        <th colspan="3">购物车</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>商品名称</td>
                        <td>商品数量</td>
                        <td>商品价格</td>
                    </tr>
                    <tr v-for="(phone,index) in goodsList">
                        <td>{{phone.name}}</td>
                        <td><input type="text" v-model.number="phone.num"></td>
                        <!-- <td>{{phone.num}}</td> -->
                        <td>{{phone.price}}</td>
                    </tr>
                    <tr>
                        <td>小结</td>
                        <td>{{getTotalNum}}件</td>
                        <td>{{ getTotalPrice}}元</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <script src='./vue.js'></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                //购物车
                goodlist: [{
                    name: 'iphone12',
                    price: 5999,
                    num: 10
                }, {
                    name: 'Mi11',
                    price: 3999,
                    num: 50
                }, {
                    name: 'Huawei',
                    price: 6999,
                    num: 80
                }, {
                    name: 'oppo',
                    price: 2999,
                    num: 8
                }, ]
            },
            computed: {
                getTotalNum() {
                    let num = 0;
                    this.goodlist.forEach(item => {
                        num += item.num
                    });
                    return num;
                },
                getTotalPrice() {
                    let num = 0;
                    this.goodlist.forEach(item => {
                        num += item.num * item.price
                    });
                    return num;
                }
            }
        })
    </script>
</body>

</html>